<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>API Test Page</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            line-height: 1.6;
            margin: 0;
            padding: 20px;
            color: #333;
            background-color: #f8f9fa;
        }
        .container {
            max-width: 800px;
            margin: 40px auto;
            background-color: #fff;
            padding: 30px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }
        h1 {
            color: #007bff;
            text-align: center;
            margin-bottom: 30px;
        }
        .btn {
            display: inline-block;
            background-color: #007bff;
            color: #fff;
            padding: 10px 20px;
            text-decoration: none;
            border-radius: 5px;
            border: none;
            cursor: pointer;
            font-size: 16px;
            margin: 10px;
        }
        .btn:hover {
            background-color: #0069d9;
        }
        #result {
            margin-top: 20px;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 5px;
            background-color: #f5f5f5;
            min-height: 100px;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>API Test Page</h1>
        
        <div>
            <button id="testHealth" class="btn">Test Health Endpoint</button>
            <button id="testRegister" class="btn">Test Registration</button>
        </div>
        
        <div id="result">
            <p>Results will appear here...</p>
        </div>
    </div>

    <script>
        document.getElementById('testHealth').addEventListener('click', function() {
            const resultDiv = document.getElementById('result');
            resultDiv.innerHTML = '<p>Testing health endpoint...</p>';
            
            // Get the base URL dynamically
            const baseUrl = window.location.pathname.includes('/file-transfer') ? 
                            '/file-transfer' : '';
            
            fetch(`${baseUrl}/api/users/health`)
                .then(response => {
                    resultDiv.innerHTML += `<p>Response status: ${response.status}</p>`;
                    return response.text();
                })
                .then(data => {
                    resultDiv.innerHTML += `<p>Response data: ${data}</p>`;
                })
                .catch(error => {
                    resultDiv.innerHTML += `<p>Error: ${error.message}</p>`;
                });
        });
        
        document.getElementById('testRegister').addEventListener('click', function() {
            const resultDiv = document.getElementById('result');
            resultDiv.innerHTML = '<p>Testing registration endpoint...</p>';
            
            const user = {
                username: "testuser",
                email: "test@example.com",
                password: "password123"
            };
            
            // Get the base URL dynamically
            const baseUrl = window.location.pathname.includes('/file-transfer') ? 
                            '/file-transfer' : '';
            
            // Log the request URL
            const requestUrl = `${baseUrl}/api/users/register`;
            resultDiv.innerHTML += `<p>Request URL: ${requestUrl}</p>`;
            
            fetch(requestUrl, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(user)
            })
            .then(response => {
                resultDiv.innerHTML += `<p>Response status: ${response.status}</p>`;
                return response.text();
            })
            .then(data => {
                resultDiv.innerHTML += `<p>Response data: ${data}</p>`;
            })
            .catch(error => {
                resultDiv.innerHTML += `<p>Error: ${error.message}</p>`;
            });
        });
    </script>
</body>
</html> 